package com.lp.compt.controllers;

import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.beans.factory.annotation.Autowired;
import com.lp.compt.pojo.SsNoticeEntity;
import com.lp.compt.services.SsNoticeEntityService;

import java.util.HashMap;
import java.util.Map;

/**
 * 服务类
 *
 * @author
 * @since 1.0.0
 */
@RestController
@CrossOrigin
@RequestMapping("/ssNoticeEntity")
public class SsNoticeEntityController {

    final
    SsNoticeEntityService ssNoticeEntityService;

    public SsNoticeEntityController(SsNoticeEntityService ssNoticeEntityService) {
        this.ssNoticeEntityService = ssNoticeEntityService;
    }

    /**
     * 根据SsNoticeEntity的字段,自动生成条件,字段的值为null不生成条件
     * http://localhost:8080/user/?id=1
     *
     * @param ssNoticeEntity 实体对象
     * @param pageable       分页/排序对象
     * @return 返回的是实体, 里面涵盖分页信息及状态码
     */
    @GetMapping
    ResponseEntity<Object> search(SsNoticeEntity ssNoticeEntity, Pageable pageable) {
        return ssNoticeEntityService.search(ssNoticeEntity, pageable);
    }

    @PostMapping
    Map create(@RequestBody SsNoticeEntity ssNoticeEntity) {
        ssNoticeEntityService.save(ssNoticeEntity);
        return new HashMap() {{
            put("code", 200);
            put("msg", "添加成功");
        }};
    }

    @PostMapping("del")
    Map del(@RequestBody SsNoticeEntity ssNoticeEntity) {
        ssNoticeEntityService.del(ssNoticeEntity);
        return new HashMap() {{
            put("code", 200);
            put("msg", "添加成功");
        }};
    }

    @PutMapping
    void update() {
    }

    @DeleteMapping("/")
    void delete() {
    }
}
